import java.util.Map;
import java.util.Scanner;

public class Main {

    public static int[] getNextArray(char[] ms) {
        if (ms.length == 1) {
            return new int[] { -1 };
        }
        int[] next = new int[ms.length + 1];
        next[0] = -1;
        next[1] = 0;
        int i = 2;
        int cn = 0;
        while (i <= ms.length) {
            if (ms[i - 1] == ms[cn]) {
                next[i++] = ++cn;
            } else if (cn > 0) {
                cn = next[cn];
            } else {
                next[i++] = 0;
            }
        }
        return next;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        char[] str = s.toCharArray();
        int[] Next = getNextArray(str);
        int m = s.length();
        if (m == 1) {
            System.out.println("Just a legend");
        } else {
            int vis[] = new int[m + 10];
            for (int i = 1; i < m; i++) {
                vis[Next[i]]++;
            }

            boolean flag = false;
            int i = m;
            while (Next[i] > 0) {
                if (vis[Next[i]] > 0) {
                    for (int j = 0; j < Next[i]; j++) {
                        System.out.print(str[j]);
                    }
                    System.out.println();
                    flag = true;
                    break;
                }
                i = Next[i];
            }
            if (!flag) {
                System.out.println("Just a legend");
            }
        }
    }

}
